package com.hblack.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hblack.manage.pojo.ItemParamItem;
import com.hblack.manage.service.ItemParamItemService;

@Controller
@RequestMapping(value="item/param/item")
public class ItemParamItemController {
	
	@Autowired
	private ItemParamItemService itemParamItemService;
	
	/**
	 * 根据商品id查询商品规格参数
	 * @param itemId
	 * @return
	 */
	@RequestMapping(value="{itemId}")
	public ResponseEntity<ItemParamItem> queryByItemId(@PathVariable("itemId") Long itemId){
		
		try {
			ItemParamItem itemParamItem = new ItemParamItem();
			itemParamItem.setItemId(itemId);
			
			ItemParamItem queryOne = itemParamItemService.queryOne(itemParamItem);
			if(queryOne == null) {
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
			}
			return ResponseEntity.ok(queryOne);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	}
	
}
